
#include "cuckoofilter.h"

#include <assert.h>
#include <math.h>

#include <iostream>
#include <vector>



int main(int argc, char **argv) {
  size_t totalItems = 1000000;

  // Create a cuckoo filter where each item is of type size_t and
  // use 12 bits for each item:
  //    CuckooFilter<size_t, 12> filter(total_items);
  // To enable semi-sorting, define the storage of cuckoo filter to be
  // PackedTable, accepting keys of size_t type and making 13 bits
  // for each key:
  //   CuckooFilter<size_t, 13, cuckoofilter::PackedTable> filter(total_items);
  CuckooFilter<size_t, 12> filter(totalItems);

  // Insert items to this cuckoo filter
  size_t numInserted = 0;
  for (size_t i = 0; i < totalItems; i++, numInserted++) {
	if (filter.Add(i) != OK) {
	  break;
	}
  }

  // Check if previously inserted items are in the filter, expected
  // true for all items
  for (size_t i = 0; i < numInserted; i++) {
	assert(filter.Contain(i) == OK);
  }

  // Check non-existing items, a few false positives expected
  size_t totalQueries = 0;
  size_t falseQueries = 0;
  for (size_t i = totalItems; i < 2 * totalItems; i++) {
	if (filter.Contain(i) == OK) {
	  falseQueries++;
	}
	totalQueries++;
  }

  // Output the measured false positive rate
  std::cout << "false positive rate is "
			<< 100.0 * falseQueries / totalQueries << "%\n";

  return 0;
}
